import time
import pytest
from DYing.day11_pytest.conftest import *
from selenium import webdriver
from  selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class Test_Buer:

    @pytest.fixture(scope='function',autouse=True)
    def setup_teardown(self):
        self.driver = webdriver.Chrome()
        self.driver.get(url)
        self.driver.implicitly_wait(10)
        self.driver.maximize_window()
        yield self.driver
        self.driver.quit()
    @pytest.fixture(scope='function',autouse=True)
    def test_login(self):
        # 登录点击体验一下
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_element_located(login_ele)).click()
        time.sleep(2)
        text = WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located(login_text)).text
        assert text=='快速菜单'
    def test_user_del(self):
        # 销售页面选中一条数据删除
        # 点击销售
        WebDriverWait(self.driver,10,0.5).until(EC.presence_of_all_elements_located(user_del_ele))[0].click()
        #点击销售预定
        WebDriverWait(self.driver,10,0.5).until(EC.presence_of_all_elements_located(user_del_c1_ele))[1].click()
        time.sleep(2)
        # 勾选
        WebDriverWait(self.driver,10,0.5).until(EC.presence_of_all_elements_located(user_del_c2_ele))[2].click()
        # 删除
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_element_located(user_del_c3_ele)).click()
        # 确定删除
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located(user_del_button_ele))[-1].click()

        time.sleep(4)
    def test_click_off(self):
        #  点击关闭，关闭该条数据
        # 点击销售
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located(user_del_ele))[0].click()
        # 点击销售预定
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located(user_del_c1_ele))[1].click()
        time.sleep(2)
        # 点击编号
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located(user_del_button_ele))[22].click()
        time.sleep(2)
        # 点击确定关闭
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located(user_del_button_ele))[-1].click()
    def test_click_code(self):
        # 点击编号跳转到销售预定详情页
        # 点击销售
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located(user_del_ele))[0].click()
        # 点击销售预定
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located(user_del_c1_ele))[1].click()
        time.sleep(2)
        # 点击编号
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located(user_del_button_ele))[23].click()
        time.sleep(2)
    def test_click_switch(self):
        # 点击转销售--跳转到新增订单转销售单
        # 点击销售
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located(user_del_ele))[0].click()
        # 点击销售预定
        WebDriverWait(self.driver, 10, 0.5).until(
            EC.presence_of_all_elements_located(user_del_c1_ele))[1].click()
        time.sleep(2)
        # 点击编号
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located(user_del_button_ele))[21].click()
        time.sleep(2)
